<html>
<head>
    <#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <!-- Bootstrap Core CSS -->
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .verify-tip{display: none; margin-top: 5px; margin-bottom: 10px; color: #a94442;font-size: 85%;}
        #loginName{ width: auto; border-radius: 0 4px 4px 0;}
        .text-warning{ line-height: 32px;}
        .jq_tips_box{ padding: 5px !important;}
        .jq_tips_info{ background: #fff !important; border: none !important; box-shadow: none !important; color: #a94442 !important;}
        .jq_tips_arrow{ display: none !important;}
        .font{font-size: 10px;}
    </style>
</head>
<body class="font">
<div id="page-wrapper" style="padding: 0 15px;">
    <div class="row">
        <div class="col-lg-12">
            <br>
            <div class="panel panel-default">
                <div class="panel-body">
                    <form role="myForm">
                        <input type="hidden" id="_ctx" value="${basePath}"/>
                        <div class="form-group input-group" >
                            <span class="input-group-addon">登录名</span>
                            <input type="text"  class="form-control" name="loginName" id="loginName" maxlength="11">
                        </div>
                        <span class="text-warning">（修改后登录名称将变为新设置名称，敬请牢记！）</span></br>
                            手机号码: ${phone!}
                                <input type ="hidden" name="phone" id="phone" value="${phone!}"  />
                            <!-- <button class="btn"  id = "numberCode" name = "numberCode" style = "color:red">获取验证码</button> -->
                                <span class="code-btn"  style = "color:red" >获取验证码</span>
                              <span></span></br>
                            <span></span></br>
                            <span>输入验证码: <input type="text"  style="width:105px; margin:0px 0px 0px 12px;height:22px;border-radius:4px; border:1px solid #DBDBDB ;"  maxlength = "6" name= "verificationCode"  id="verificationCode"></span>
                        <div class="form-group input-group"></div>
                        <span class="verify-tip">该登录名已存在!</span>
                        <hr>
                        <div class="row" align="center">
                            <div class="col-xs-12">
                                <button type="button" class="btn btn-primary" onclick="submitForm();">确定</button>
                                <button type="button" class="btn btn-info" onclick="closePage();">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${basePath}/bootstrap/js/jquery.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
   <script type="text/javascript" src="${basePath}/bootstrap/js/jquery.tips.js"></script>
<!-- layer JavaScript -->
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //关闭窗口并刷新页面
    function closePage() {
        parent.layer.close(index);
    }

    function submitForm() {
    //登录名验证
     var obj = $('#loginName').val().trim();
    	 if(obj==""){
             $("#loginName").tips({
                    side:3,
                    msg:'登录名不能为空',
                    time:5,
                });
                return false;
         }
         else if(/0?(13|14|15|17|18)[0-9]{9}/.test(obj) == false){
             $("#loginName").tips({
                 side:3,
                 msg:'登录名必须是11位手机号',
                 time:5,
             });
             return false;
         }
        $.ajax({
            type:'POST',
            url: '${basePath}/admin/manager/changeLoginName',
            dataType: 'json',
            data:{loginName:$('#loginName').val()},
            success: function (data) {
                 if (data.code == '0' || data.code == '0000') {
                    layer.alert('修改登录名成功，请重新登录', {
                        icon : 6
                    });
                    setTimeout(function () {
                        top.location.href = '${basePath}/admin/logout';
                    }, 1000);
                }else{
                    layer.alert(data.desc, {
                        icon : 5
                    });
                }
            },
            error: function(){

            }
        });
    }



    //获取验证码
    $(".code-btn").click(function(){
        var tel = $("#phone").val();
        var obj = $('#loginName').val().trim();
        var verificationCode = $('#verificationCode').val().trim();
        if(obj==""){
            $("#loginName").tips({
                side:3,
                msg:'登录名不能为空',
                time:5,
            });
            return false;
        }
        if(!regTel.test(tel)){
            alert("请输入正确的手机号码");
            return false;
        }
        else{
            getCode(tel);
        }
    });

    //获取验证码
    var codeStatus = true;
    var appUrl = $("#_ctx").val();
    function getCode(tel){
        if(codeStatus){
            codeStatus = false;
            $.ajax({
                type: 'GET',
                url: appUrl+'/merchant/sendCode?account='+tel+'&imageCodeType=41',
                dataType: 'json',
                cache: false,
                success: function(data) {
                    if(data.code == "0"){
                        Count($(".code-btn"));
                    }
                    else if(data.code == "00001026"){
                        alert("该手机号已占用!")
                    }else
                        layer.alert(data.desc, {
                            icon : 5
                        });
                },
                error: function(){
                    alert("获取验证码失败")
                }
            })
        }
    }
    //倒计时
    var Count = function(obj){
        var time = 60;//时间
        //定义时间
        var t = setInterval(function(){
            time --;
            obj.html(time + "s后重试");
            if(time > 0){
                obj.off("click");
                obj.css("background-color","#ccc");
            }
            else if(time == 0){
                clearInterval(t);
                obj.css("background-color","#FFBE34");
                obj.html("重新获取");
                codeStatus = true;
                obj.off("click").on("click",function(){
                    var tel = $("#tel").val();
                    getCode(tel);
                });
            }
        },1000);
    };

</script>
</body>
</html>

